'use strict';
// eslint-disable-next-line jsdoc/require-param
/**
 * 增加数据
 */
exports.create = async ctx => {
  ctx.validate({
    type: {
      type: 'enum',
      values: [ 'FOLDER', 'SUB_FOLDER', 'FILE' ],
    },
    title: {
      type: 'string',
      min: 1,
      max: 20,
    },
    icon: {
      type: 'string',
      min: 1,
      max: 40,
    },
    index: {
      type: 'number',
      min: 0,
      max: 9,
      convertType: 'number',
    },
    describe: {
      type: 'string',
      max: 140,
      required: false,
    },
    superId: {
      type: 'mongo-id',
      required: false,
    },
    path: {
      type: 'string',
      min: 1,
      max: 40,
    },
  });
  const data = await ctx.service.authPage.create();
  ctx.sendSuccess(data);
};

exports.index = async ctx => {
  const data = await ctx.service.authPage.all();
  ctx.sendSuccess(data);
};

// eslint-disable-next-line jsdoc/require-param
/**
 * 删除
 */
exports.destroy = async ctx => {
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  const data = await ctx.service.authPage.destroy();
  ctx.sendSuccess(data);
};

// eslint-disable-next-line jsdoc/require-param
/**
 * 更新
 */
exports.update = async ctx => {
  ctx.validate({
    type: {
      type: 'enum',
      values: [ 'FOLDER', 'SUB_FOLDER', 'FILE' ],
    },
    title: {
      type: 'string',
      min: 1,
      max: 20,
    },
    icon: {
      type: 'string',
      min: 1,
      max: 40,
    },
    index: {
      type: 'number',
      min: 0,
      max: 9,
      convertType: 'number',
    },
    describe: {
      type: 'string',
      max: 140,
      required: false,
    },
    path: {
      type: 'string',
      min: 1,
      max: 40,
    },
  });
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  const data = await ctx.service.authPage.update();
  ctx.sendSuccess(data);
};
